/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */
import Vue from "vue";
import  { Tooltip } from 'view-design'

//页面状态相关
let status = {
  modalAssign:{
    isShow : false,
    isLoading : false
  },
  modalCustomerInfo:{
    isShow : false,
    isLoading : false
  },
  modalSearchTag:{
    isShow : false,
    type:1,//标签类型
    selectedTags:[],
    selectedOtherTags:[]
  }
};

// 和网络交互相关的参数
let params = {
  searchParams:{
    userState:120,
    contactUrl:"",
    employeeName:"",
    employeeId:"",
    number:"",
    isNotAssigned : false,
    isHasShop : false,
    country:"",
    tags : "",
    otherTags:""
  },
  selectedUsers:[],
  selectedEmployee:{}
};

// 页面的数据源
let data = {
  userList: [],
  employeeList :[],
  customerInfo : {
    id: "",
    name: "",
    contactUrl:"",
    externalEmail: "",
    customerDesc: "",
    isSendLetter: false,
    state: 0,
    externalUrl:'', //个人主页
    extendInfo:{
      followerCount:0,//粉丝数
      followingCount:0,//关注数
      description:'',
      alexa:0,	//网站排名
      country:'',	//网站国家编码
      title:'',	//网站标题
      siteDesc:'',//原网站描述
      extra:'',//网站扩展信息
      facebook:'',
      twitter:'',
      instagram:'',
      pinterest:''
    },
    tags:[],//可维护标签
    readonlyTags:[],//抓取到的网站标签
    otherTags:[],//其他标签
    contacts:[],
    opRecords:[]
  }
};

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 60,
  currentPage: 1
};

//客户列表
let userTableTitles=function (self) {
  return [
    {
      type: 'selection',
      align: 'center',
      fixed: 'left',
      width: 60
    },
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    // {
    //   title: '用户名',
    //   width: 180,
    //   key: 'name',
    //   align:'center',
    //   render: (h, params) => {
    //     let hasAuth = self.$authority("OPERATIONS-2-201");
    //     let userName = params.row.name? params.row.name :"";
    //     let hideName = Vue.prototype.$tiyHideUsername(userName);
    //     if (!hasAuth){
    //       return (
    //         <div>
    //         // <Tooltip content={userName} placement="top">
    //         {hideName}
    //         // </Tooltip>
    //         </div>
    //     );
    //     } else{
    //       return (
    //         <div>
    //         <Tooltip content={hideName} placement="top">
    //         <a style="padding:6px;font-size:13px" onClick={() => {self.getCustomerDetail(params.row.id, params.row.state);}}>
    //       {hideName}
    //     </a>
    //       </Tooltip>
    //       </div>
    //     );
    //     };
    //   }
    // },
    {
      title: '独立站编号',
      width: 200,
      key: 'number',
      align:'center',
      render: (h, params) => {
        let hasAuth = self.$authority("OPERATIONS-2-201");
        if (!hasAuth){
          return (<div>{params.row.number}</div>);
        } else{
          return (
            <div>
              <a onClick={() => {self.getCustomerDetail(params.row.id, params.row.state);}}>{params.row.number}</a>
            </div>
          );
        };
      }
    },

    {
      title: '独立站',
      key: 'externalUrl',
      width: 120,
      align:'center',
      render: (h, params) => {
        let externalUrl = params.row.externalUrl;
        if (!externalUrl){
          return (
            <div><span></span></div>
          );
        }else{
          return (
            <div>
              <Tooltip content={externalUrl} placement="top">
                <a target='_blank' href={externalUrl}> 点击访问 </a>
              </Tooltip>
            </div>
          );
        }
      }
    },
    // {
    //   title: '独立站标签',
    //   key: 'tags',
    //   align: 'center',
    //   width: 120,
    //   render: (h, params) => {
    //     return h('div', [h('Tooltip', {
    //       props: {content: params.row.tags, placement: 'right', "max-width":"300"},
    //       style: {display: params.row.tags? "block" : "none",fontSize:"font-size:0.8rem;"},
    //     }, '查看'),
    //     ]);
    //   }
    // },



    // {
    //   title: '沟通次数',
    //   width: 100,
    //   key: 'contactCount',
    //   align:'center'
    // },
    {
      title: '站内信地址',
      key: 'contactUrl',
      width: 120,
      align:'center',
      render: (h, params) => {
        return params.row.contactUrl ? h("div", [h('a', {
          attrs: {
            target: "_blank", href: params.row.contactUrl
          }
        }, "点击访问")]) : h("div", "");
      }
    },
    {
      title: '国家',
      width: 80,
      key: 'country',
      align:'center',
      render: (h, params) => {
        return params.row.country ? (<div>{params.row.country}</div>) : (<div></div>);
      }
    },
    {
      title: '邮箱',
      width: 100,
      key: 'externalEmail',
      align:'center',
      render: (h, params) => {
        return params.row.externalEmail?h("div","有邮箱"):h("div","无");
      }
    },
    {
      title: '负责员工',
      width: 140,
      key: 'employeeName',
      align:'center',
    },
    {
      title: '状态',
      width: 140,
      key: 'state',
      align:'center',
      render:(h, params) =>{
        return h('div', self.targetCustomerStateDict.filter(item => item.value == params.row.state)[0].name);
      }
    },
   // {
   //   title: '导入时间',
   //   width: 150,
   //   key: 'createtime',
   //   align:'center',
   //   render: (h, params) => {
   //     let date = new Date(params.row.createtime);
   //   }
   // }
  ];
};


//员工列表
let employeeTableTitles=function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '员工',
      width: 200,
      key: 'userName',
    },
    {
      title: '角色',
      width: 160,
      key: 'roleName',
    },
  ];
};

//记录列表
let recordTable=function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '员工',
      width: 140,
      key: 'employeeName',
    },
    {
      title: '操作',
      width: 160,
      key: 'operation',
      render: (h, params) => {
        return h('div', self.customerOperationDict.filter(item => item.value == params.row.operation)[0].name);
      }
    },
    {
      title: '备注',
      key: 'notes'
    },
    {
      title: '操作时间',
      width: 140,
      key: 'createtime',
      render: (h, params) => {
        return h('div',self.$tiyBJTime(params.row.createtime));
      }
    },
  ];
};

let role = {
};

export  default  {
  tStatus: status,
  tParams: params,
  tData: data,
  tPage: page,
  userTableTitles:userTableTitles,
  employeeTableTitles:employeeTableTitles,
  recordTable : recordTable
};
